// pages/accountdetail/accountdetail.js
const HTTP = require('../../utils/util');
const common = require('../../libs/common');
Page({

    /**
     * 页面的初始数据
     */
    data: {
        accountList: [],
        type: 1,
        active: 0,
        limit: 10,
        page1: 1,
        page2: 1,
        loading:true,
    },
    //页面触底
    onReachBottom() {
        let page1 = this.data.page1;
        let page2 = this.data.page2;
        if (Number(this.data.active) === 0) {
            this.setData({
                page1: page1 + 1
            });
            this.getAccountDetail(page1);
        } else if (Number(this.data.active) === 1) {
            this.setData({
                page2: page2 + 1
            });
            this.getAccountDetail(page2);
        }
    },
    onTabChange(e) {
        let page1 = this.data.page1;
        let page2 = this.data.page2;
        if (e.detail.index === 0) {
            this.setData({
                active: 0
            });
            this.getAccountDetail(page1);
        } else if (e.detail.index === 1) {
            this.setData({
                active: 1
            });
            this.getAccountDetail(page2);
        }
    },
    getAccountDetail(page) {
        this.setData({
            loading:true
        });
        HTTP.getData('/api/person/account', {
            type: this.data.active + 1,
            page: page,
            limit: 10
        }, res => {
            common.handlePageChange(page,res.data.data,this.data.accountList,(e)=>{
                this.setData({
                    accountList:e,
                    loading:false
                });
            },'记录')
        });
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {

    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        this.getAccountDetail(this.data.page1);
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})